<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/fabric@4.6.0/dist/fabric.min.js"></script>
</head>
<body>
  <!-- <img src="https://img1.baidu.com/it/u=3206351602,2714439067&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" alt=""> -->
  <!-- <img src="./assets/imgs/Snipaste_2022-10-25_11-11-58.png" alt=""> -->
  <canvas width="800" height="600" id="canvas" style="border: 1px solid #ccc;"></canvas>
  <script>
    let canvas = new fabric.Canvas('canvas')
    // 圆
    let circle = new fabric.Circle({
      left: 100,
      top: 100,
      radius: 50,
    })
    // 线性渐变
    let gradient = new fabric.Gradient({
      type: 'radial', // linear or radial
      coords: { 
        r1: 50, // 该属性仅径向渐变可用，外圆半径
        r2: 0, // 该属性仅径向渐变可用，外圆半径
        x1: 50, // 焦点的x坐标
        y1: 50, // 焦点的y坐标
        x2: 50, // 中心点的x坐标
        y2: 50, // 中心点的y坐标
      }, 
      colorStops: [ // 定义渐变颜色组
        { offset: 0, color: 'red' },
        // { offset: 0.2, color: 'orange' },
        // { offset: 0.4, color: 'yellow' },
        // { offset: 0.6, color: 'green' },
        // { offset: 0.8, color: 'blue' },
        { offset: 1, color: 'purple' },
      ]
    })
    circle.set('fill', gradient)
    canvas.add(circle)
  </script>
</body>
</html>